#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <SDL.h>
#include "slak/glui/gl-include.h"

void makeTexture()
{
	char pixels[16*16];
	glPixelStorei(GL_UNPACK_ALIGNMENT,1);
	glTexImage2D(GL_TEXTURE_2D,
		     0, GL_RGB, 16, 16, 
		     0, GL_RGB, GL_UNSIGNED_BYTE,
		     pixels);

	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}

void draw()
{
	glClearColor(0,0,0,0);
	glClear(GL_COLOR_BUFFER_BIT);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,1024,0,768,-1,1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	glEnable(GL_TEXTURE_2D);

	glBegin(GL_QUADS);

	glColor3f(0,1,0);
	glVertex2f(20,20);
	glTexCoord2f(0,0);

	glVertex2f(1004,20);
	glTexCoord2f(1,0);
	
	glVertex2f(1004,748);
	glTexCoord2f(1,1);
	
	glVertex2f(20,748);
	glTexCoord2f(0,1);

	glEnd();

	SDL_GL_SwapBuffers();
}

int
main(int argc,char**argv)
{
	assert (SDL_Init(SDL_INIT_VIDEO) == 0);
	atexit(SDL_Quit);
	
	SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 8 );
	SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 8 );
	SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 8 );
	SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

	SDL_SetVideoMode(1024, 768, 32, SDL_OPENGL|SDL_FULLSCREEN);

	makeTexture();

	while(1) {
		SDL_Event ev;
		while(SDL_PollEvent(&ev)) {
			switch(ev.type) {
			case SDL_KEYDOWN:
				switch(ev.key.keysym.sym) {
				case SDLK_ESCAPE:
					exit(0);
					break;
				}
				break;
			}
		}

		draw();
	}
}

